//
//  scrollTouchView.m
//  自定义可动图表
//
//  Created by yuklng on 16/2/18.
//  Copyright © 2016年 yuklng. All rights reserved.
//

#import "scrollTouchView.h"

@implementation scrollTouchView{
    touchView* touchList;
}

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self setBackgroundColor:[UIColor clearColor]];
        
        touchList =[[touchView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width+1, frame.size.height+1) topLine:30 lowestLine:17 autoLayout:YES];
        
        [touchList setDelegate:self];
        
        _scroll =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        
        _scroll.bounces =NO; //禁止上下边界弹动效果
        
        _scroll.scrollEnabled =YES;  //是否可以滚动
        
//      横向滚动禁止
//        _scroll.showsHorizontalScrollIndicator =NO;
        
        _scroll.showsVerticalScrollIndicator =NO;
        
        _scroll.pagingEnabled=NO;   //是否可以翻页
        
        _scroll.showsHorizontalScrollIndicator = NO;
        
        _scroll.directionalLockEnabled = YES;
        
        _scroll.alwaysBounceVertical= NO;
        
        _scroll.contentOffset=CGPointZero;  //contentview原点距离self原点距离，这儿取的负值
        
        _scroll.contentSize =  CGSizeMake(0, touchList.frame.size.height);     //存放图片有效范围frame是（0,0,contentsize.width,contentsize.height）
        
        
        [_scroll addSubview:touchList];
        
        [super addSubview:_scroll];
        
    }

    return self;
}

-(id)initWithScopeOrData:(CGRect)frame max:(int)max min:(int)min dataArray:(NSArray*)dataArray{
    self = [super initWithFrame:frame];
    if(self){
        [self setBackgroundColor:[UIColor clearColor]];
        
        touchList =[[touchView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width+1, frame.size.height+1) topLine:max lowestLine:min autoLayout:YES];
        
        [self setDataArray:dataArray];
        
        [touchList setDelegate:self];
        
        _scroll =[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        
        _scroll.bounces =NO; //禁止上下边界弹动效果
        
        _scroll.scrollEnabled =YES;  //是否可以滚动
        
        //      横向滚动禁止
        //        _scroll.showsHorizontalScrollIndicator =NO;
        
        _scroll.showsVerticalScrollIndicator =NO;
        
        _scroll.pagingEnabled=NO;   //是否可以翻页
        
        _scroll.showsHorizontalScrollIndicator = NO;
        
        _scroll.directionalLockEnabled = YES;
        
        _scroll.alwaysBounceVertical= NO;
        
        _scroll.contentOffset=CGPointZero;  //contentview原点距离self原点距离，这儿取的负值
        
        _scroll.contentSize =  CGSizeMake(0, touchList.frame.size.height);     //存放图片有效范围frame是（0,0,contentsize.width,contentsize.height）
        
        
        [_scroll addSubview:touchList];
        
        [super addSubview:_scroll];
        
    }
    
    return self;
}

-(void)setDataArray:(NSArray*)dataArray{
//    listDataArray =[dataArray mutableCopy];
    [touchList setDataArray:dataArray];
}

-(void)setDelegate:(id)object{
    [touchList setDelegate:object];
}

-(int)getListData:(int)point{
    pointObject* pObject = touchList.cloudArray[point];
    return pObject.row;
}

-(void)setMaxRange:(int)max minRange:(int)min{
    [touchList removeFromSuperview];
    touchList =[[touchView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width+1, self.frame.size.height+1) topLine:max lowestLine:min autoLayout:YES];
    [self addSubview:touchList];
}

//代理。有需求再追加接口
-(void)touchSwitch:(BOOL)choice dataArray:(NSArray*)dataArray{
    NSLog(@"代理事件触发");
}


-(void)drawBack{
    // 创建path
    UIBezierPath* path = [UIBezierPath bezierPath];
    // 添加路径[1条点(100,100)到点(200,100)的线段]到path
    [path moveToPoint:CGPointMake(0, self.frame.size.height-6)];
    [path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height-6)];
    // 将path绘制出来
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame         = self.bounds;                // 与showView的frame一致
    layer.lineWidth     = 1.2f;                           // 线条宽度
    layer.path          = path.CGPath;                    // 从贝塞尔曲线获取到形状
    layer.strokeColor   = [UIColor whiteColor].CGColor;   // 边缘线的颜色
    layer.fillColor     = [UIColor clearColor].CGColor;   // 闭环填充的颜色
    
    [self.layer addSublayer:layer];
    
    //    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100 / 2.f, 100 / 2.f)
    //                                                        radius:100 / 2.f
    //                                                    startAngle:0
    //                                                      endAngle:M_PI * 2
    //                                                     clockwise:YES];
    //
    //
    //    // 创建一个shapeLayer
    //    CAShapeLayer *layer = [CAShapeLayer layer];
    //    layer.frame         = self.bounds;                // 与showView的frame一致
    //    layer.strokeColor   = [UIColor greenColor].CGColor;   // 边缘线的颜色
    //    layer.fillColor     = [UIColor clearColor].CGColor;   // 闭环填充的颜色
    //    layer.lineCap       = kCALineCapSquare;               // 边缘线的类型
    //    layer.path          = path.CGPath;                    // 从贝塞尔曲线获取到形状
    //    layer.lineWidth     = 4.0f;                           // 线条宽度
    //    layer.strokeStart   = 0.0f;
    //    layer.strokeEnd     = 0.1f;
    
}

@end
